package com.yanqu.road.server.logic.activity.condition.recharge;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.config.goods.GetRechargeMallResult;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.ePlayerAttrType;
import com.yanqu.road.entity.task.args.ManorRechargeArgs;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.gameplayer.module.player.AttributeModule;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;

import java.math.BigInteger;

/**
 * @author ：zfr
 * @date ：2021/9/2 16:35
 */
public class RechargeManorCondition extends BaseActivityCondition {

    public RechargeManorCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.RechargeManor.getValue(), handle);

    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.RechargeManor.getValue(), handle);
    }

    public boolean isCompleted(GamePlayer player) {
        return getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0;
    }

    public void setMallInfo() {
        GetRechargeMallResult result = player.getModule(ActivityModule.class).getShowRMBMallInfo(activityConditionInfo);
        if (result.isDuringCd()) {
            return;
        }
        if (result.getMallInfo() != null) {
            player.getModule(AttributeModule.class).setAttribute(ePlayerAttrType.ManorRechargeTriggerTimes, 0);
        }
        setRMBMallActivityInfo(result.getMallInfo());
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        ManorRechargeArgs args = (ManorRechargeArgs)object;
        if (args.getType() == 0) {  //充值购买礼包触发
            //加道具，设置购买状态
            if(getValue().intValue() == args.getValue()) {
                getRMBMallActivityReward(args.getValue());
            }
        } else if (args.getType() == 1) {
            if (getValue().compareTo(BigInteger.ZERO) == 0) {
                setMallInfo();
            }
        } else if (args.getType() == 2) {
            if (getValue().compareTo(BigInteger.ZERO) == 0) {
                long param4 = activityConditionInfo.getParamList().get(3).longValue();
                if (player.getModule(AttributeModule.class).getAttribute(ePlayerAttrType.ManorRechargeTriggerTimes) >= param4) {
                    setMallInfo();
                }
            }
        }
    }
}
